package com.youyi.yyviewsdklibrary.View;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v4.internal.view.SupportMenu;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class MyRectView extends View {
    private int bottom = 500;
    private float currentX = 0.0f;
    private float currentY = 0.0f;
    private int left = 200;
    private final int mScreenHeight;
    private final int mScreenWidth;
    private boolean onHorizontalDownStroke = false;
    private boolean onHorizontalUpStroke = false;
    private boolean onVerticalLeftStroke = false;
    private boolean onVerticalRightStroke = false;
    private Paint paint;
    private Rect rect;
    private int right = 700;
    private int strokeWidth = 10;

    /* renamed from: top  reason: collision with root package name */
    private int f75top = 200;

    public MyRectView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        init();
        this.mScreenWidth = context.getResources().getDisplayMetrics().widthPixels;
        this.mScreenHeight = context.getResources().getDisplayMetrics().heightPixels;
    }

    private void init() {
        Paint paint2 = new Paint();
        this.paint = paint2;
        paint2.setStrokeWidth((float) this.strokeWidth);
        this.paint.setColor(-65536);
        this.paint.setStyle(Paint.Style.STROKE);
        this.rect = new Rect(this.left, this.f75top, this.right, this.bottom);
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(this.rect, this.paint);
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        float x = motionEvent.getX();
        float y = motionEvent.getY();
        int action = motionEvent.getAction();
        if (action == 0) {
            this.currentX = x;
            this.currentY = y;
            onHorizontalRectStroke(x, y);
            onVerticalRectStroke(x, y);
        } else if (action == 1) {
            this.onHorizontalUpStroke = false;
            this.onHorizontalDownStroke = false;
            this.onVerticalLeftStroke = false;
            this.onVerticalRightStroke = false;
        } else if (action == 2) {
            this.currentX = x;
            this.currentY = y;
            moveRectStroke();
        }
        return true;
    }

    private void moveRectStroke() {
        if (this.onVerticalLeftStroke) {
            int i = (int) this.currentX;
            this.left = i;
            if (i < 0) {
                this.left = 0;
            }
            int i2 = this.left;
            int i3 = this.right;
            if (i2 > i3 - 25) {
                this.left = i3 - 25;
            }
            redrawRect();
        } else if (this.onVerticalRightStroke) {
            int i4 = (int) this.currentX;
            this.right = i4;
            if (i4 > this.mScreenWidth) {
                this.right = 900;
            }
            int i5 = this.right;
            int i6 = this.left;
            if (i5 < i6 + 25) {
                this.right = i6 + 25;
            }
            redrawRect();
        } else if (this.onHorizontalUpStroke) {
            int i7 = (int) this.currentY;
            this.f75top = i7;
            if (i7 < 0) {
                this.f75top = 0;
            }
            int i8 = this.f75top;
            int i9 = this.bottom;
            if (i8 > i9 - 25) {
                this.f75top = i9 - 25;
            }
            redrawRect();
        } else if (this.onHorizontalDownStroke) {
            int i10 = (int) this.currentY;
            this.bottom = i10;
            if (i10 > this.mScreenHeight) {
                this.bottom = 1500;
            }
            int i11 = this.bottom;
            int i12 = this.f75top;
            if (i11 < i12 + 25) {
                this.bottom = i12 + 25;
            }
            redrawRect();
        }
    }

    private void redrawRect() {
        this.rect.set(this.left, this.f75top, this.right, this.bottom);
        invalidate();
    }

    private void onVerticalRectStroke(float f, float f2) {
        if (f2 >= ((float) this.f75top) && f2 <= ((float) this.bottom)) {
            int i = this.left;
            int i2 = this.strokeWidth;
            if (f > ((float) ((i2 * 5) + i)) || f < ((float) (i - (i2 * 5)))) {
                int i3 = this.right;
                if (f <= ((float) ((i2 * 5) + i3)) && f >= ((float) (i3 - (i2 * 5)))) {
                    this.onVerticalRightStroke = true;
                    return;
                }
                return;
            }
            this.onVerticalLeftStroke = true;
        }
    }

    private void onHorizontalRectStroke(float f, float f2) {
        if (f >= ((float) this.left) && f <= ((float) this.right)) {
            int i = this.f75top;
            int i2 = this.strokeWidth;
            if (f2 > ((float) ((i2 * 5) + i)) || f2 < ((float) (i - (i2 * 5)))) {
                int i3 = this.bottom;
                if (f2 <= ((float) ((i2 * 5) + i3)) && f2 >= ((float) (i3 - (i2 * 5)))) {
                    this.onHorizontalDownStroke = true;
                    return;
                }
                return;
            }
            this.onHorizontalUpStroke = true;
        }
    }
}
